<?php
	// Connect to mysql
	mysql_connect('testsite.untoldthegame.com:3306', 'untol1_testcb', 'Ch@racter11')
		or die(mysql_error());
	
	mysql_select_db('untol1_testcb');
	
	// Usage: execute_query("SELECT * FROM table WHERE column = %s", value)
	function execute_query($query)
	{
		$sanitized_args = array();
		
		$first_argument_index = 1;
		$argument_count = func_num_args() - $first_argument_index;
		for ($i = 0; $i < $argument_count; ++$i)
		{
			$arg = func_get_arg($first_argument_index + $i);
			$sanitized_args[$i] = mysql_real_escape_string($arg);
		}
		
		$sanitized_query = vsprintf($query, $sanitized_args);
		
		// Now that the query has been sanitized, it can be executed
		return execute_query_unsafe($sanitized_query);
	}
	
	function execute_query_unsafe($query)
	{
		//// For debugging purposes only
		//echo $query;
	
		$result = mysql_query($query);
		if (!$result)
			die(mysql_error());
		return $result;
	}
	
	function start_transaction()
	{
		execute_query_unsafe("START TRANSACTION");
	}
	
	function commit()
	{
		execute_query_unsafe("COMMIT");
	}
	
	function rollback()
	{
		execute_query_unsafe("ROLLBACK");
	}
?>
